/**
 * Created by shenyinlin on 2018/6/24.
 */


import {DataStore} from "../base/DataStore.js";
    //计分器类
export class Score{



    constructor(){

        this.ctx = DataStore.getInstance().ctx;

        this.scoreNumer = 0;

        //canvas 刷新很快,需要一个变量控制加分只加一次
        //可以加分吗?默认可以
        this.isScore = true;

    }


    draw(){
        //25px的万能字体
        this.ctx.font = '30px Arial';
        this.ctx.fillStyle = 'white';
        //最大大小1000 防止浏览器兼容有问题
        let scoreAmount =  this.scoreNumer +'';
        this.ctx.fillText(
            scoreAmount,
            DataStore.getInstance().canvas.width / 8.5,
            DataStore.getInstance().canvas.height / 18,
            1000
        );

    }

    //游戏结束时的绘制
    drawGameOver(){
        //25px的万能字体
        this.ctx.font = '30px Arial';
        this.ctx.fillStyle = 'red';
        //最大大小1000 防止浏览器兼容有问题
        let scoreAmount =  this.scoreNumer +'';
        this.ctx.fillText(
            scoreAmount,
            (DataStore.getInstance().canvas.width ) / 1.65,
            (DataStore.getInstance().canvas.height) / 2.75,
            1000
        );

    }



    drawGameOverFont(){
        //25px的万能字体
        this.ctx.font = '30px Arial';
        this.ctx.fillStyle = 'black';

        //最大大小1000 防止浏览器兼容有问题
        let scoreAmount =  this.scoreNumer +'';
        let classFont = '';
        if(scoreAmount<20){
            classFont = 'E';
        }
        if(scoreAmount>20 && scoreAmount<40){
            classFont = 'D';
        }
        if(scoreAmount>40 && scoreAmount<60){
            classFont = 'C';
            this.ctx.fillStyle = 'green';
        }
        if(scoreAmount>60){
            classFont = 'B';
            this.ctx.fillStyle = 'blue';
        }
        if(scoreAmount>80){
            classFont = 'A';
            this.ctx.fillStyle = 'orange';
        }
        if(scoreAmount>100){
            classFont = 'S';
            this.ctx.fillStyle = 'red';
        }
        if(scoreAmount>200){
            classFont = 'S+';
            this.ctx.fillStyle = 'red';
        }
        if(scoreAmount>300){
            classFont = 'SSS';
            this.ctx.fillStyle = 'red';
        }

        this.ctx.fillText(
            classFont,
            (DataStore.getInstance().canvas.width ) / 1.65,
            (DataStore.getInstance().canvas.height) / 2.15,
            1000
        );

    }



    //更改是否能够加分
    updateIsScore(){
        this.isScore = !this.isScore;
    }
    //获取目前的加分flag
    getIsScore(){
        return this.isScore;
    }

    //返回当前积分
    getNowScore(){
        return this.scoreNumer;
    }

    //加分
    addScore(){
      this.scoreNumer = this.scoreNumer + parseInt(10 * Math.random()); 
        wx.vibrateShort({
         "success":function(){
            console.log('震动了一下...');
          }
        });
    }

}